package com.yykj.drup.server.controller;


import com.yykj.common.vo.ResultVO;
import com.yykj.drup.server.dto.CategoryTreeDto;
import com.yykj.drup.server.model.Category;
import com.yykj.drup.server.param.StoreCategorysParam;
import com.yykj.drup.server.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zengg
 * @since 2022-03-10
 */
@Api(tags = "药品分类")
@RequestMapping("/api/drug")
@AllArgsConstructor
@RestController
public class CategoryController {

    final CategoryService categoryService;

    @ApiOperation("查询分类树结构")
    @GetMapping("/category/findCategoryTree")
    @ApiImplicitParam(name = "categoryType",value = "1：西药， 2：中药",required = true)
    public ResultVO<CategoryTreeDto> findCategoryTree(
            @RequestParam(name = "categoryType") Integer categoryType
    ){
        return ResultVO.success(categoryService.getCategoryTree(categoryType));
    }

    @Deprecated
    @ApiOperation("查询全部分类列表（暂时不用）")
    @GetMapping("/category/findCategorys")
    @ApiImplicitParam(name = "categoryType",value = "1：西药， 2：中药",required = true)
    public ResultVO<Category> findCategorys(@RequestParam(name = "categoryType") Integer categoryType){
        return ResultVO.success(categoryService.getCategory(categoryType));
    }

    @ApiOperation("查询药店二级分类及药品列表（患者端）")
    @PostMapping("/category/findStoreCategorys")
    public ResultVO<Category> findStoreCategorys(@RequestBody  @Valid StoreCategorysParam param){
        return ResultVO.success(categoryService.getStoreCategory(param.getCategoryType(),param.getStoreId()));
    }
}
